/**
 * Created by Administrator on 2017/5/26.
 */


var gulp =require('gulp');
var connect = require('gulp-connect');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require("gulp-rename");


var jsSrc='./js/*.js';
var jsDist= './dist/js';
var htmlSrc='./*.html';
var htmlDist='./dist';
var cssSrc='./css/*.css';
var cssDist='./dist/css';


gulp.task('js',function(){
   gulp.src(jsSrc)
       .pipe(concat('index.js'))
       .pipe(gulp.dest(jsDist))
       .pipe(rename({suffix:'.min'}))
       .pipe(uglify())
       .pipe(gulp.dest(jsDist))
       .pipe(connect.reload())
});

gulp.task('html',function(){
    console.log("调用html了");
    gulp.src(htmlSrc)
        .pipe(gulp.dest(htmlDist))
        .pipe(connect.reload())
});

gulp.task('css',function(){
    console.log("调用css了");
    gulp.src(cssSrc)
        .pipe(concat('index.css'))
        .pipe(gulp.dest(cssDist))
        .pipe(rename({suffix:'.min'}))
        .pipe(gulp.dest(cssDist))
        .pipe(connect.reload())
});

gulp.task('connect', function() {
    connect.server({
        livereload: true,
        port:8182
    });
});

gulp.task('watch',function(){
    gulp.watch('./*.html',['html']);
    gulp.watch('./css/*.css',['css']);
    gulp.watch('./js/*.js',['js'])
});


gulp.task('default',['js','html','connect','watch','css']);






